package com.google.shoopinggoods.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.shoppinggoods.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/10/13.
 */

public abstract class BaseActivity extends AppCompatActivity {

    private View back;
    private TextView tv_title;
    private TextView tv_title_right;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        initTitileBar();
        setListener();
        initData();
    }

    //初始化标题
    private void initTitileBar() {
        back = findViewById(R.id.back);
        tv_title = (TextView) findViewById(R.id.tv_tile);
        tv_title_right = (TextView) findViewById(R.id.tv_tile_right);
    }

    public void showTitle(boolean showTitle, String title, String s) {
        if (showTitle){
            back.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onLeftBtnClick();
                }
            });
        }else{
            back.setVisibility(View.GONE);
        }

        if (tv_title!=null&& !TextUtils.isEmpty(title)){
            tv_title.setText(title);
        }

        if (tv_title_right!=null&& !TextUtils.isEmpty(s)){
            tv_title_right.setText(s);
            tv_title.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onRightTitleClick();
                }
            });
        }

    }

    public void onRightTitleClick() {

    }

    private void onLeftBtnClick() {
        finish();
    }

    public abstract int getLayoutId();

    protected abstract void setListener();

    protected abstract void initData();

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
